﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
using DevExpress.XtraReports;
using DevExpress.XtraReports.UI;
namespace Exact_VAS
{
    public partial class BankPaymentVoucherForm : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        public BankPaymentVoucherForm(ExactDataContext _DS)
        {
            InitializeComponent();
            DS = _DS;
            this.InitializeData();

        }
        private void InitializeData()
        {
            var queryJournal = from Journal in DS.dagbks
                               
                               select Journal;
            this.dagbkBindingSource.DataSource = queryJournal;


            if (queryJournal.Count() > 0)
            {
                this.lookUpEdit_Journal.EditValue = queryJournal.First().dagbknr;
            }
           
                             
        }

        private void lookUpEdit_Journal_EditValueChanged(object sender, EventArgs e)
        {

            var queryEntry = from Entry in DS.ISHCMC_V_BankPaymentVouchers
                             where Entry.JournalNumber == Convert.ToString(this.lookUpEdit_Journal.EditValue)
                             select Entry;
            this.iSHCMCVBankPaymentVoucherBindingSource.DataSource = queryEntry;
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (this.gridView1_EntryNumber.GetSelectedRows().Length > 0)
            {
                ISHCMC_V_BankPaymentVoucher itemPayment = (ISHCMC_V_BankPaymentVoucher)this.gridView1_EntryNumber.GetRow(this.gridView1_EntryNumber.GetSelectedRows()[0]);
                if (this.cbxBank.Text== "CBA")
                {
                    PaymentOrderCBARpt rpt = new PaymentOrderCBARpt();
                    rpt.LoadDataSource(itemPayment);
                    ReportPrintTool ReportPrint = new ReportPrintTool(rpt);
                    ReportPrint.ShowPreview();
                }
                if (this.cbxBank.Text == "VCB")
                {
                    PaymentOrderVCBRpt rpt = new PaymentOrderVCBRpt();
                    rpt.LoadDataSource(itemPayment);
                    ReportPrintTool ReportPrint = new ReportPrintTool(rpt);
                    ReportPrint.ShowPreview();
                }
                if (this.cbxBank.Text == "ANZ")
                {
                    PaymentOrderANZRpt rpt = new PaymentOrderANZRpt();
                    rpt.LoadDataSource(itemPayment);
                    ReportPrintTool ReportPrint = new ReportPrintTool(rpt);
                    ReportPrint.ShowPreview();
                }


            }
        }

        private void btnFCAmount_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if(this.gridView1_EntryNumber.GetSelectedRows().Length >0)
            {
                
                    ISHCMC_V_BankPaymentVoucher itemBPV = (ISHCMC_V_BankPaymentVoucher)this.gridView1_EntryNumber.GetRow(this.gridView1_EntryNumber.GetSelectedRows()[0]);
                     UpdateFCAmountMsg Msg = new UpdateFCAmountMsg(DS,itemBPV);

                      DialogResult result = Msg.ShowDialog();
                      if(result == DialogResult.No)
                      {
                          MessageBox.Show("Update FC Amount occured error , please check again !");
                      }
            }
        }

        private void gridView1_EntryNumber_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                this.popupMenu1.ShowPopup(Control.MousePosition);
               
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            var queryEntry = from Entry in DS.ISHCMC_V_BankPaymentVouchers
                             where Entry.JournalNumber == Convert.ToString(this.lookUpEdit_Journal.EditValue)
                             select Entry;
            this.iSHCMCVBankPaymentVoucherBindingSource.DataSource = queryEntry;
        }
    }
}